package com.test.hystrix.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: spring-cloud-demo
 * @description: hystrix 断路器测试
 * @author: lyr
 * @create: 2018-06-06 10:02
 **/
@Service
public class HystrixTestService {


    @HystrixCommand(fallbackMethod = "fallback", commandProperties = {
            //timeoutInMilliseconds 使用线程隔离时，调用超时时间
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1000")
    })
    public Object hystrixTest(String hello){
        if (hello.equals("hello")) {
            throw new RuntimeException("fail now");
        }
        Map result = new HashMap<String, String>();
        result.put("value", hello);
        return result;
    }

    public Object fallback(String hello) {
        Map result = new HashMap<String, String>();
        result.put("value", "this is fallback result!!!!!!!!!!!");
        return result;
    }

}
